/**
 * @Date: 2022-03-07 13:06:21
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-03-14 10:50:24
 * @FilePath: \zhihuReal\routes\users.js
 * @Description: 用户路由
 */
// @ts-nocheck
const router = require('koa-router')()
const {
  getUserCtl,
  getUserByIdCtl,
  createUserCtl,
  updateUserCtl,
  deleteUserCtl,
  Userlogin,
  cheackOwner,
  followingList,
  follow,
  unFollow,
  followerList,
  followTopic,
  unFollowTopic,
  followingTopicList,
  questionList,
  unFollowQuestion,
  followQuestion,
  likeAnswersList,
  LikeAnswers,
  disLikeAnswers,
  unlikeAnswersList,
  unLikeAnswers,
  disunlikeAnswers,
  collectionAnswersList,
  collectionAnswers,
  disCollectionAnswers,
  unlikeCommentList,
  unLikeComment,
  disunlikeComment,
  collectionCommentList,
  collectionComment,
  disCollectionComment,
  likeCommentList,
  LikeComment,
  disLikeComment
} = require('../controllers/userCtl')
const {
  auth
} = require('../middlewares/auth')
const {
  cheackUserExist,
  cheackTopicExist,
  cheackQuestionExist,
  cheackAnswerExist,
  cheackCommentExist
} = require('../middlewares/cheack')
router.prefix('/user')
router.get('/', async (ctx) => {
  ctx.body = await getUserCtl(ctx)
})
router.post('/', async (ctx) => {
  ctx.body = await createUserCtl(ctx)
})
router.get('/:id', async (ctx) => {
  ctx.body = await getUserByIdCtl(ctx)
})
router.patch('/:id', auth, cheackOwner, async (ctx) => {
  ctx.body = await updateUserCtl(ctx)
})
router.delete('/:id', auth, cheackOwner, async (ctx) => {
  const code = await deleteUserCtl(ctx)
  ctx.status = code
})
router.post('/login', async (ctx) => {
  const user = await Userlogin(ctx)
  ctx.body = user
})
router.get('/:id/followingList', async (ctx) => {
  const user = await followingList(ctx)
  ctx.body = user
})
router.put('/following/:id', auth, cheackUserExist, async (ctx) => {
  await follow(ctx)
})
router.delete('/following/:id', auth, cheackUserExist, async (ctx) => {
  await unFollow(ctx)
})
router.put('/followTopic/:id', auth, cheackTopicExist, followTopic)
router.delete('/followTopic/:id', auth, cheackTopicExist, unFollowTopic)
router.put('/followQuestion/:id', auth, cheackQuestionExist, followQuestion)
router.delete('/followQuestion/:id', auth, cheackQuestionExist, unFollowQuestion)
router.get('/:id/followerList', async (ctx) => {
  const list = await followerList(ctx)
  ctx.body = list
})
//关注话题列表
router.get('/:id/followTopicList', auth, followingTopicList)
//问题列表
router.get('/:id/questionList', auth, questionList)
//喜欢的答案列表
router.get('/:id/likeAnswersList', likeAnswersList)
//踩的答案列表
router.get('/:id/unlikeAnswersList', unlikeAnswersList)
//踩的评论列表
router.get('/:id/unlikeCommentList', unlikeCommentList)
//点赞答案
router.put('/likeAnswersList/:id', auth, cheackAnswerExist, LikeAnswers, disunlikeAnswers)
//点赞评论
router.put('/LikeComment/:id', auth, cheackCommentExist, LikeComment, disunlikeComment)
//取消点赞答案
router.delete('/likeAnswersList/:id', auth, cheackAnswerExist, disLikeAnswers)
//取消点赞评论
router.delete('/LikeComment/:id', auth, cheackCommentExist, disLikeComment)
//踩答案
router.put('/unlikeAnswersList/:id', auth, cheackAnswerExist, unLikeAnswers, disLikeAnswers)
//踩评论
router.put('/unlikeCommentList/:id', auth, cheackCommentExist, unLikeComment, disLikeComment)
//取消踩答案
router.delete('/unlikeAnswersList/:id', auth, cheackAnswerExist, disunlikeAnswers)
//取消踩评论
router.delete('/unlikeCommentList/:id', auth, cheackCommentExist, disunlikeComment)
//收藏答案
router.put('/collectAnswerList/:id', auth, cheackAnswerExist, collectionAnswers)
//收藏评论
router.put('/collectionCommentList/:id', auth, cheackCommentExist, collectionComment)
//取消收藏答案
router.delete('/collectAnswerList/:id', auth, cheackAnswerExist, disCollectionAnswers)
//取消收藏评论
router.delete('/collectionCommentList/:id', auth, cheackCommentExist, disCollectionComment)
//获取收藏的答案列表
router.get('/:id/collectAnswerList', collectionAnswersList)
//获取收藏的评论列表
router.get('/:id/collectionCommentList', collectionCommentList)
//获取点赞的评论列表
router.get('/:id/likeCommentList', likeCommentList)
module.exports = router